﻿using UnityEngine.UI;
using UnityEngine;

class SelectPanelExt:PanelBase
{
    private Monster monster;
    private Image hpImg;
    private Text hpText;

    public override void RegisterListeners()
    {
        base.RegisterListeners();
        hpImg = transform.Find("HpFiller").GetComponent<Image>();
        hpText = transform.Find("HpText").GetComponent<Text>();
    }

    public override void PanelUpdate()
    {
        base.PanelUpdate();
        monster = Mgr.monsterMgr.GetMonsterById(monster.MonsterId);
        if(monster != null)
        {
            SetHp(monster.info.Health, monster.MaxHealth);

            if(Vector3.Distance(monster.transform.position, Mgr.mainPlayer.transform.position) > 20f)
            {
                Mgr.selectTargetMgr.ClearSelect();
            }
        }
        else
        {
            Mgr.selectTargetMgr.ClearSelect();
        }
    }

    public void SetFightObj(SceneFightObject obj)
    {
        if(obj is Monster)
        {
            monster = obj as Monster;
            SetHp(monster.info.Health, monster.MaxHealth);
        }
    }

    private void SetHp(int curhp, int maxhp)
    {
        hpImg.fillAmount = (float)curhp / maxhp;
        hpText.text = curhp + "/" + maxhp + " XP";
    }
}